package com.thuanpq60023.easyenglish.global;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import android.app.Activity;
import android.content.SharedPreferences;

public class GlobalFunction {
	public static String getCurrentDate() {
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy/MM/dd HH:mm:ss");
		String createdate = dateFormat.format(Calendar.getInstance().getTime());
		return createdate;
	}

	public static String getLastVisit(Activity mActivity) {
		String lstVisit = "2012/01/01 00:00:00";
		SharedPreferences myprefs = mActivity.getSharedPreferences(
				GlobalConstant.SHARED_PREF_NAME, 0);

		if (myprefs != null) {

			lstVisit = myprefs.getString(GlobalConstant.SHARED_PREF_LASTVISIT,
					"2012/01/01 00:00:00");

			// Update new string of time
			SharedPreferences.Editor mEditor = myprefs.edit();
			mEditor.putString(GlobalConstant.SHARED_PREF_LASTVISIT,
					GlobalFunction.getCurrentDate());
			mEditor.commit();
		}
		return lstVisit;
	}
}
